<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activId']))
{
  header("location:checklogin.php");
}

//Insert Query of Transaction In 
if(isset($_POST['insertBtn']))
{  
  $transactionIn  = (isset($_POST['transactionIn'])) && ($_POST['transactionIn'] != "") ? $_POST['transactionIn'] : 0 ;
  $insertQuerydriver = "INSERT INTO transactionin (branchId,transactionIn)
                             VALUES('".$_SESSION['ses_branchId']."','".$transactionIn."')";
  $insertQuerydriverdResult = mysql_query($insertQuerydriver);
  if(!$insertQuerydriverdResult)
    die("Insert Query Not Inserted : ".mysql_error());
  else
  {
    //header("Location:drivermaster.php");
  }
}
  //Select Query of Transaction In
  $transactionInArray = array();
  $i = 0;
  $selectTransaction = "SELECT transactionInId,transactionIn,branch.branchName
                          FROM transactionin
                        LEFT JOIN branch ON branch.branchId = transactionin.branchId
                        ORDER BY branchName";
  $selectTransactionRes  = mysql_query($selectTransaction);
  while($transactionInRow = mysql_fetch_array($selectTransactionRes))
  {
    $transactionInArray[$i]['transactionInId'] = $transactionInRow['transactionInId'];
    $transactionInArray[$i]['transactionIn']   = $transactionInRow['transactionIn'];
    $transactionInArray[$i]['branchName']      = $transactionInRow['branchName'];
    $i++;
  }
  
  $k = 0;
  $branchArray = array();
  $slectBranch = "SELECT branchId,branchName
                    FROM branch";
  $slectBranchRes = mysql_query($slectBranch);
  while($branchRow = mysql_fetch_array($slectBranchRes))
  {
  	$branchArray['branchId'][$k]   = $branchRow['branchId'];
  	$branchArray['branchName'][$k] = $branchRow['branchName'];
  	$k++;
  }
include("./bottom.php");
$smarty->assign('branchIdSelected',$_SESSION['ses_branchId']);
$smarty->assign('branchNameSelected',$_SESSION['ses_branchName']);
$smarty->assign("transactionInArray",$transactionInArray);  
$smarty->assign("branchArray",$branchArray);  
$smarty->display('transactionIn.tpl');
?>